// Author: wsfuyibing <682805@qq.com>
// Date: 2025-05-15

package purchase_list

import (
	"server/app/http/models"
	"server/app/kind"
)

// Response
// 出参.
type Response struct {
	Id            int64
	ArcadeId      kind.ArcadeId
	GoodsId       kind.GoodsId
	PurchasePrice kind.Balance
	PurchaseCost  kind.Balance
	PurchaseCount kind.GoodsStock
	LockedCount   kind.GoodsStock
	SaleCount     kind.GoodsStock
	SaleTotal     kind.GoodsStock
	SaleOut       bool
	Remaining     kind.GoodsStock
	CreateTime    string
}

// With
// 绑定数据.
func (o *Response) With(m *models.GoodsPurchase) *Response {
	o.Id = m.Id
	o.GoodsId = m.GoodsId
	o.PurchasePrice = m.PurchasePrice
	o.PurchaseCount = m.PurchaseCount
	o.PurchaseCost = m.PurchaseCost
	o.LockedCount = m.LockedCount
	o.SaleCount = m.SaleCount
	o.SaleTotal = m.SaleTotal
	o.CreateTime = m.CreatedAt.Time().Format("2006/01/02 15:04")

	o.Remaining = m.PurchaseCount - m.SaleCount - m.LockedCount
	o.SaleOut = o.Remaining <= 0
	return o
}
